package cn.tedu.shoppingmall.mapper;

import cn.tedu.shoppingmall.vo.Comment;
import org.apache.ibatis.annotations.Insert;

import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.mapstruct.Mapper;

import java.util.List;

@Mapper
public interface CommentMapper{
    //新增评论
    @Insert("insert into comment(comid,usernick,userurl,title,content,level,url) values(#{comid},#{usernick},#{userurl},#{title},#{content},#{level},#{url})")
    void insert(Comment comment);

    //good-1
    @Update("update comment set good=good-1 where id=#{id}")
    int delGood(int id);
    //good+1
    @Update("update comment set good=good+1 where id=#{id}")
    int addGood(int id);
    //no-1
    @Update("update comment set no=no-1 where id=#{id}")
    int delNo(int id);
    //no+1
    @Update("update comment set no=no+1 where id=#{id}")
    int addNo(int id);


    //查询所有评论列表
    @Select("select * from comment where comid=#{comid} order by created asc")
    List<Comment> findAll(int comid);
    //查询单个评论
    @Select("select * from comment where id=#{id}")
    Comment findOneById(int id);
}
